public class SumNodeValFromRootToLeaves {
    private int sum=0;
    public int sumNumbers(TreeNode root) {
        return dfs(root, 0);
    }
    public int dfs(TreeNode root, int cur) {
        if (root == null) return 0;
        if (root.left == null && root.right == null) return cur * 10 + root.val;
        int left = dfs(root.left, cur * 10 + root.val);
        int right = dfs(root.right, cur * 10 + root.val);
        return left + right;
    }
}
